package com.zyk.leetcode;

/**
 *
 * https://leetcode-cn.com/problems/consecutive-characters/
 *
 * @author zhangsan
 * @date 2021/3/24 11:11
 */
public class C1446 {

    public static int maxPower(String s) {
        if(s == null || s.length() == 0) {
            return -1;
        }
        int max = 0;
        int len = 1;
        char[] str = s.toCharArray();
        char pre = str[0];
        for (int i = 1; i < str.length; i++) {
            if(str[i] == pre) {
                len++;
            }else {
                max = Math.max(max, len);
                len = 1;
                pre = str[i];
            }
        }
        max = Math.max(max, len);
        return max;
    }

    public static int maxPower2(String s) {
        if(s == null || s.length() == 0) {
            return -1;
        }
        int max = 0;
        char[] str = s.toCharArray();
        for (int i = 0; i < str.length; i++) {
            int j = i+1;
            while (j < str.length && str[i] == str[j]) {
                j++;
            }
            max = Math.max(max, j-i);
        }
        return max;
    }

    public static void main(String[] args) {
        String s = "abbcccddddeeeeedcba";
        System.out.println(maxPower(s));
        System.out.println(maxPower2(s));
    }

}
